package com.sskj.tibi.ui.fragment;


import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ImgUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.util.CopyUtil;
import com.sskj.lib.util.ImageUtil;
import com.sskj.tibi.R;
import com.sskj.tibi.R2;
import com.sskj.tibi.bean.RechargeBean;
import com.sskj.tibi.presenter.RechargeFragmentPresenter;

import butterknife.BindView;


@Route(path = RConfig.TIBI_FRAGMENT_RECHARGE)//充币
public class RechargeFragment extends BaseFragment<RechargeFragmentPresenter> {

    @BindView(R2.id.ivQR)
    ImageView ivQR;
    @BindView(R2.id.tvAddress)
    TextView tvAddress;
    @BindView(R2.id.tvCopy)
    TextView tvCopy;
    @BindView(R2.id.tvDesc)
    TextView tvDesc;
    @BindView(R2.id.tvSave)
    TextView tvSave;

    @Override
    protected int getLayoutId() {
        return R.layout.tibi_fragment_recharge;
    }

    @Override
    public RechargeFragmentPresenter getPresenter() {
        return new RechargeFragmentPresenter();
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        mPresenter.getData();
    }

    public void updateUI(RechargeBean data) {
        ImageUtil.setImage(data.getCodeUrlImg(),ivQR);
//        QRCodeUtil.createImage(data.getCodeUrlImg(), 400, new QRCodeUtil.OnEncodeQRCodeCallback() {
//            @Override
//            public void onAnalyzeSuccess(Bitmap bitmap) {
//                ivQR.setImageBitmap(bitmap);
//            }
//
//            @Override
//            public void onAnalyzeFailed() {
//
//            }
//        });

        ClickUtil.click(tvSave, () -> {
            ImgUtil.saveImageToGallery(getActivity(), ivQR);

        });
        tvAddress.setText(data.getAddr());
        ClickUtil.click(tvCopy, () -> {
            CopyUtil.copy(data.getAddr());
        });

    }


}
